
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../common.dart';



class HomePage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('首页'),
        centerTitle: true,
        actions: [
          IconButton(
            icon: Icon(Icons.settings),   
            onPressed: () => Navigator.pushNamed(context, '/settings'),
          )
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              child: Text('商品列表'),
              onPressed: () {
 
                toNamed('/details?id=123&name=Flutter');

                // Navigator.push(
                //   context,
                //   MaterialPageRoute(builder: (context) => ProductListPage()),
                // );
              }, 
            ),
            SizedBox(height: 20),
            ElevatedButton(
              child: Text('用户中心'),
              onPressed: () {
                print('object');
                eventBus.fire(UserLoginEvent('JohnDoeddd'));
                Get.back();
              },
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () => _showAddDialog(context),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.search), label: '搜索'),
        ],
        currentIndex: 0,
        onTap: (index) {
          if (index == 1) {
             
          }else{
            toNamed('/');

          }
        },
      ),
    );
  }

  void _showAddDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (context) => AlertDialog(
        title: Text('新建项目'),
        content: TextField(decoration: InputDecoration(hintText: '输入名称')),
        actions: [
          TextButton(
            child: Text('取消'),
            onPressed: () => Navigator.pop(context),
          ),
          TextButton(
            child: Text('确定'),
            onPressed: () {
              // 处理新建逻辑
              Navigator.pop(context);
            },
          ),
        ],
      ),
    );
  }
}


class ProductDetailPage extends StatelessWidget {
  final int id;
  ProductDetailPage({required this.id});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('商品详情')),
      body: Center(child: Text('商品ID: $id')),
    );
  }
}
